import { BadRequestException } from "@nestjs/common";
import { Transform } from "class-transformer";

export function TransformDate() {
  return Transform(({ value, key }) => {
    if (!value) return value;

    try {
      return new Date(value).toISOString();
    } catch (error) {
      throw new BadRequestException(`${key}:数据格式错误`);
    }
  });
}
